/*
 * @Author: guoyangf
 * @Date: 2020-05-28 14:52:23
 * @LastEditTime: 2020-09-21 15:12:05
 * @Description: file content
 */
import { requestPromise } from 'src/erm/sscrppublic/common/utils/asyncFunctions.js';

import {
    toast,
} from 'nc-lightapp-front';

/**
 * @method query 获取配置信息
 * @return {Object} 出参报文
 */
async function getConfig(data) {
    try {
        const result = await requestPromise({
            url: `/nccloud/ssctp/sscbd/SSCTaskHandleConfigAction.do`,
            data
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })
    }
}

/**
 * @method query 查询数据
 * @return {Object} 出参报文
 */
async function query(data) {
    try {
        const result = await requestPromise({
            url: `/nccloud/ssctp/sscbd/SSCTaskHandleQueryByTaskTypeAction.do`,
            data
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })
    }
}

/**
 * @method query 询问pk列表是否变化。 仅待处理页签需要询问
 * @return {Object} 出参报文
 */
async function inquiryPksIsChange(data) {
    try {
        const result = await requestPromise({
            url: `/nccloud/ssctp/sscbd/SSCTaskHandleAddNoticeAction.do`,
            data,
            loading: false
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })
    }
}

/**
 * 根据pk查询列表数据。
 * 用于翻页
 *
 * @param {*} data
 * @returns
 */
async function queryByPks(data) {
    try {
        const result = await requestPromise({
            url: `/nccloud/ssctp/sscbd/SSCTaskHandleQueryByPKTaskAction.do`,
            data,
            hasErrCallBack: true
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })
    }
}

/**
 * @method query 扫码查询
 * @return {Object} 出参报文
 */
async function queryByBarCode(data) {
    try {
        const result = await requestPromise({
            url: `/nccloud/ssctp/sscbd/SSCTaskBarCodeScanAction.do`,
            data
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })
    }
}


/**
 * @method query 打开单据
 * @return {Object} 出参报文
 */
async function openBill(data) {
    try {
        const result = await requestPromise({
            url: `/nccloud/ssctp/sscbd/SSCTaskBrowseBillAction.do`,
            data
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })
    }
}

/**
 *定向查询
 *提取
 * @returns
 */
async function taskTakeAction(data) {
    try {
        const result = await requestPromise({
            url: '/nccloud/ssctp/sscbd/SSCTaskHandleTakeAction.do',
            data
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })

    }
}

// 暂存
async function saveTemp(data) {
    try {
        const result = await requestPromise({
            url: '/nccloud/sscqm/checkbill/CheckBillSidebarSaveAction.do',
            data
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })

    }


}

// 审核 我的审核 我的作业
async function taskApproveAction(data, factor) {

    try {
        const result = await requestPromise({
            url: '/nccloud/' + factor + '/ssctp/sscbd/SSCTaskHandleApproveAction.do',
            data
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })

    }
}

// 取消审核 我的审核 我的作业
async function taskUnApproveAction(data, factor) {
    try {
        const result = await requestPromise({
            url: '/nccloud/' + factor + '/ssctp/sscbd/SSCTaskHandleUnApproveAction.do',
            data
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })

    }
}


// 稽核
async function audit(data) {
    try {
        const result = await requestPromise({
            url: '/nccloud/sscqm/checkbill/CheckBillSidebarSaveAction.do',
            data
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })

    }
}

// 取消稽核
async function cancelAudit(data) {
    try {
        const result = await requestPromise({
            url: '/nccloud/sscqm/checkbill/CheckBillSidebarUnSaveAction.do',
            data
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })

    }
}

// 整改
async function rectify(data) {
    try {
        const result = await requestPromise({
            url: '/nccloud/sscqm/checkbill/CheckBillSidebarRectifyAction.do',
            data
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })

    }
}

// 取消整改
async function cancelRectify(data) {
    try {
        const result = await requestPromise({
            url: '/nccloud/sscqm/checkbill/CheckBillSidebarUnRectifyAction.do',
            data
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })

    }
}

/* 以下为我的打印接口 */
//退回
async function printDelete(data) {
    try {
        const result = await requestPromise({
            url: '/nccloud/ssctp/print/PrintDeleteAction.do',
            data
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })
    }
}

//取消打印
async function printCancel(data) {
    try {
        const result = await requestPromise({
            url: '/nccloud/ssctp/print/PrintCancelAction.do',
            data
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })
    }
}

//获取打印信息
async function printInfo(data) {
    try {
        const result = await requestPromise({
            url: '/nccloud/riart/print/taskinfo.do',
            data,
            loading: false
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })
    }
}

//是否安装影像和外系统
async function checkImageInstalled(data) {
    try {
        const result = await requestPromise({
            url: '/nccloud/ssctp/dapsystem/DapSystemInstalled4ImageAction.do',
            data,
            loading: false
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })
    }
}

//外系统凭证和影像接口
async function imagAndVoucherOps(data) {
    try {
        const result = await requestPromise({
            url: '/nccloud/ssctp/dapsystem/TryReqImageAndVoucherShowTypeAction.do',
            data,
            loading: false
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })
    }
}


// 取得子页面控制列表刷新注册信息
async function apiRefreshList(data) {
    try {
        const result = await requestPromise({
            url: '/nccloud/sscrp/rpbill/RPRefreshActionQueryAction.do',
            data,
            loading: false
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })
    }
}

// 更新ts
async function updateTs(data) {
    try {
        const result = await requestPromise({
            url: '/nccloud/ssctp/sscbd/SSCUpdateTaskAction.do',
            data
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })
    }
}

async function manualReasonQry(data){
    try {
        const result = await requestPromise({
            url: '/nccloud/ssctp/sscapv/TransToManualReasonQryAction.do',
            data
        });
        return result
    } catch (e) {
        toast({ title: e.message, duration: 5, color: 'danger', })
    }
}

export default {
    queryByPks, inquiryPksIsChange, apiRefreshList, updateTs, manualReasonQry,
    getConfig, query, openBill, taskTakeAction, queryByBarCode, saveTemp, audit, cancelAudit, rectify, cancelRectify
    , printDelete, printCancel, printInfo
    , taskApproveAction, taskUnApproveAction, checkImageInstalled, imagAndVoucherOps
};